package yuejian_07.yuejian_07.model;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import yuejian_07.yuejian_07.RetrofitListener;
import yuejian_07.yuejian_07.javabean.Notice;
import yuejian_07.yuejian_07.service.NoticeService;

/**
 * Created by dell on 2017/10/30.
 */

public class NoticeModel {
    private Retrofit retrofit;
    public NoticeModel(){
        retrofit=new Retrofit.Builder()
                .baseUrl("http://10.0.2.2/neu1_yuejian/index.php/Api/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    public void noticelist(final RetrofitListener listener) {
        NoticeService noticeService = retrofit.create(NoticeService.class);
        Call call = noticeService.getNotice();
        Callback<List<Notice>> callback = new Callback<List<Notice>>() {
            @Override
            public void onResponse(Call<List<Notice>> call, Response<List<Notice>> response) {
                List<Notice> data = response.body();
                listener.onSuccess(data);//userId这里有问题
            }

            @Override
            public void onFailure(Call<List<Notice>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }
}
